package cn.edu.sjtu.se.dslab.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import cn.edu.sjtu.se.dslab.component.data.AvionicsEquipment;
import cn.edu.sjtu.se.dslab.component.data.EquipmentPropertyInstance;
import cn.edu.sjtu.se.dslab.dao.IBaseDao;
import cn.edu.sjtu.se.dslab.dao.IEquipmentPropertyInstanceDao;

/**
 * 
 * @author longshaohang
 * 
 */
@Repository("equipmentPropertyInstanceDao")
public class EquipmentPropertyInstanceDaoImpl implements
		IEquipmentPropertyInstanceDao {

	@Resource(name = "baseDao")
	private IBaseDao<EquipmentPropertyInstance> baseDao;

	@Override
	public void save(EquipmentPropertyInstance instance) {
		baseDao.save(instance);
	}

	@Override
	public void update(EquipmentPropertyInstance instance) {
		baseDao.update(instance);
	}

	@Override
	public EquipmentPropertyInstance queryById(long id) {
		return baseDao.queryById(EquipmentPropertyInstance.class, id);
	}

	@Override
	public List<EquipmentPropertyInstance> queryByEquipment(
			AvionicsEquipment equipment) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer();
		// 拼接sql语句
		hql.append("from EquipmentPropertyInstance a where ");
		hql.append(" a.equipment.id=");
		hql.append("" + equipment.getId());
		return baseDao.query(hql.toString());
	}

}
